Imports System.Data.SqlClient

Friend Class DBServer
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load(ByRef oObject As Server)
        Dim sSQL As String = "select"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [IsActive],"
        sSQL = sSQL & "     [IsDeleted],"
        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDServers"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oObject
                .Name = oData.Rows(0).Item("Name")
                .Desc = NullToString(oData.Rows(0).Item("Desc"))
                .IsActive = oData.Rows(0).Item("IsActive")

                .IsDeleted = oData.Rows(0).Item("IsDeleted")
                .CreateName = oData.Rows(0).Item("CreateName")
                .CreateDate = oData.Rows(0).Item("CreateDate")
                .ChangeName = NullToString(oData.Rows(0).Item("ChangeName"))
                .ChangeDate = NullToString(oData.Rows(0).Item("ChangeDate"))
            End With
        Else
            oObject._ObjectExists = False
        End If

        oData.Dispose()
    End Sub

    Public Sub Update(ByRef oObject As Server)
        Dim sSQL As String = "update tDDServers set"
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & "     [Desc]=" & ValueToDBValue(oObject.Desc) & ","
        sSQL = sSQL & "     [IsActive]=" & BooleanToBit(oObject.IsActive) & ","

        sSQL = sSQL & "     [IsDeleted]=" & BooleanToBit(oObject.IsDeleted) & ","
        sSQL = sSQL & "     [CreateName]=" & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & "     [CreateDate]=" & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & "     [ChangeName]=" & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & "     [ChangeDate]=" & ValueToDBValue(oObject.ChangeDate)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Add(ByRef oObject As Server)
        Dim oNextID As New DBNextIDValue("Server")
        Dim lNextID As Long = oNextID.NextValue
        oObject.ID = lNextID

        Dim sSQL As String = "insert into tDDServers ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [IsActive],"

        sSQL = sSQL & "     [IsDeleted],"
        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Desc) & ","
        sSQL = sSQL & BooleanToBit(oObject.IsActive) & ","

        sSQL = sSQL & BooleanToBit(oObject.IsDeleted) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As Server)
        Dim sSQL As String = "delete from tDDServers"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
